package util.datautil;

import android.content.Context;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
import util.GreenTreeNetworkUtil;
import util.RequestDataCallback;
import util.StringUtil;
import util.Url;

/**
 * Created by Administrator on 2016/5/30.
 * 登入的数据
 */
public class RegisterData {
    private  RegisterInterface mRegisterInterface;
    private static RegisterData mRegisterData = new RegisterData();
    public static RegisterData getInstance(){return mRegisterData;}

    /**
     * 获取登入页背景地址
     */
    public void RegisterBackround(final Context context,String ul){
        String ur = ul+Url.REGISTER_BACKROUND;
        Map<String,Object> map = new HashMap();
        map.put("Stringurl", ur);
        GreenTreeNetworkUtil.getInstance().doPost(context,ur,1,map, new RequestDataCallback(){

            @Override public void onSuccess(String response){
                if(response !=null){
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        String url = jsonObject.getString("pic");
                        mRegisterInterface.getHomeData(url);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override public void onFailure(Throwable error){
                StringUtil.getStringUtilNew().getExceptionCode(context, error.toString());
            }
        });
    }

    /**
     * 登入页背景地址接口回调
     */
    public interface RegisterInterface{
        void getHomeData(String string);
    }

    public void setRegisterlistener(RegisterInterface homeDataInterface){
        this.mRegisterInterface = homeDataInterface;

    }
}
